var serveUrl = require('../../../utils/util.js').serveUrl;
var app = getApp()

Page({
  data:{
     userInfo: {},
    item: {
      signinHidden:false,
      userlocal:{
       nickName:'',
       nickPwd:''
     },
    },
    showView:false,
    userHeadUrl:"/images/ios/tx@2x.png",
    userName:"周伯通",
    showModalStatus: false,
    nullHouse: true,  //先设置隐藏
    messageList:[],
    deliverList:[],
    country:"",
    province:"",
    sex:"",
    language:""

  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    console.log(app.globalData.userInfo);
    
    var that=this;
    
    that.setData({
      userHeadUrl: app.globalData.userInfo.avatarUrl,
      userName: app.globalData.userInfo.nickName,
    })
    // 判断用户是否注册，如果没注册，提醒其注册
    that.isHave();
    // 用户的消息记录；
    that.messageRecord()
    // 用户的投递记录
    that.toudiRecord()
   
  },
  modalconfirm:function(){
    wx.setStorageSync('username', this.data.item.userlocal.nickName);
    wx.setStorageSync('password', this.data.item.userlocal.nickPwd);
    this.setData({
      'item.signinHidden':true
    })
  },
  // 遮罩取消
  powerDrawer1: function () {
    var that = this;
    that.setData(
      {
        showModalStatus: false
      })

  },
  // 判断简历
  isHave(){
    var that =this;
    wx.request({
      url: serveUrl + "get_cv_data_by_openid",
      data: {
        openid: app.globalData.opeid
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      success: function (res) {
        console.log("oooooo")

        console.log(res);
        if(res.data.data==""){
            that.setData({
                  country: app.globalData.userInfo.country,
                  province: app.globalData.userInfo.province,
                  sex: (app.globalData.userInfo.gender==2?"女":"男"),
                  language: app.globalData.userInfo.language
                })
        }else{
             that.setData({
               country: res.data.data[0].job_age,
               province: res.data.data[0].job_position,
                sex: res.data.data[0].tel,
                language: res.data.data[0].company
              })
        }
     
      }
    })

  },
  // 去填写个人信息
  powerDrawer: function () {
    var that = this;
    var datas = [];
    var obj = {};
    obj.title = '填写个人信息';
    obj.recruitId = '';
    datas.push(obj)
    var that = this;
    // that.setData(
    //   {
    //     showModalStatus: false
    //   })
    wx.navigateTo({
      url: "../myInfos/myInfos?canshu=" + JSON.stringify(datas),
      success: function (res) {
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })

  },
  // 判断是否注册
  isReg(){
    var that=this;
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 3000
    });
    console.log(app.globalData.userInfo)
    wx.request({
      url: serveUrl + "get_user_data",
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        wx.hideToast();

        console.log("pppppppp")
        console.log(res);
        var userDataList=res.data.data;
        for(var i=0;i<userDataList.length;i++){
          // if (userDataList[i].openid!="543228"){
          //   that.setData({
          //     showModalStatus: true
          //   })
          // }else{
          //   console.log("已经注册了")
          // }
        }
      }
    })
  },
  // 消息记录
  messageRecord(){
    var that=this;
    wx.request({
      url: serveUrl + 'get_message_by_openid',
      data:{
        openid: app.globalData.opeid
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      success: function (res) {
       console.log(res)
      //  var messageList=res.data;
      //  console.log(messageList)
       that.setData({
         messageList: res.data.data
       })
      }
    })
  },
  // 投递记录
  toudiRecord(){
    var that = this;
    wx.request({
      url: serveUrl + "get_deliver_by_openid",
      data: {
        openid: app.globalData.opeid
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      success: function (res) {
        console.log("oooooo")

        console.log(res)
        that.setData({
          deliverList: res.data.data
        })
      }
    })
  },
  // 修改个人信息
  editPersonal(){
    var that = this;
    var datas = [];
    var obj = {};
    obj.title = '修改个人信息';
    obj.recruitId = '';
    datas.push(obj)
    wx.request({
      url: serveUrl + "get_cv_data_by_openid",
      data: {
        openid: app.globalData.opeid
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      success: function (res) {
        console.log("oooooo")

        console.log(res)
        // that.setData({
        //   deliverList: res.data.data
        // })
            wx.navigateTo({
              url: "../myInfos/myInfos?canshu=" + datas,
              success: function (res) {
              },
              fail: function () {
                // fail
              },
              complete: function () {
                // complete
              }
            })
      }
    })

  },
  // 差看详情
  watchInfoTap(e){
    console.log(e)
    
    var that=this;
     that.setData({
      showView: (!that.data.showView)
    })
  },
  modalcancel:function(){
     var that = this;
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
             
               that.setData({
        userInfo:res.userInfo
      })
            }
          })
        }
      })
     
   
    this.onShow();
     this.setData({
      'item.signinHidden':true
    })
  },
  quit:function(){
    this.setData({
        userInfo:'',
        'item.signinHidden':false
      })
  },
  saveusername:function(event){
    this.setData({
      'item.userlocal.nickName': event.detail.value
    });
  },
  saveuserpwd:function(event){
    this.setData({
      'item.userlocal.nickPwd': event.detail.value
    });
  },
  onReady:function(){
   
    // 页面渲染完成
  },
  onShow:function(){
    if(this.data.userInfo==''){
      this.setData({
      'item.signinHidden':false
      })
    }

  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})